package com.wct.springcloud.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @author WEI (Email:changtan20000@163.com)
 * @description
 * @date: 2019/12/13 17:41
 */
@Slf4j
@RestController
public class ConcurrentController {

    private List<Integer> list = new ArrayList<>();

    @RequestMapping("/concurrent/add/{i}")
    public Integer add(@PathVariable("i") Integer i){
        log.info("add threadId: {}, id: {}", Thread.currentThread().getId(), i);
        log.info("hashCode: {}", this.hashCode());
        log.info("list.hashCode: {}", list.hashCode());
        return i;
    }

    @RequestMapping("/concurrent/list/add/{i}")
    public Integer addList(@PathVariable Integer i){
        list.add(i);
        log.info("addList threadId: {}, id: {}, size: {}", Thread.currentThread().getId(), i, list.size());
        return list.size();
    }
}
